package com.jinmdz.fmis.api.controller;

import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.api.model.test.BusinessData;
import com.jinmdz.fmis.api.model.test.ExportData;
import com.jinmdz.fmis.api.model.test.ValidateData;
import com.jinmdz.fmis.api.service.TestService;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.constant.EResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 测试接口
 *
 * @author LiCongLu
 * @date 2020-01-02 11:34
 */
@Api(value = "测试接口", description = "通用特殊操作的测试接口")
@RestController
@RequestMapping("/test")
public class TestController extends BaseController {

    @Resource
    private TestService testService;

    /**
     * 测试跨域访问
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-02-15 9:42
     */
    @ApiOperation(value = "测试跨域问题")
    @PostMapping("/test-origins")
    public BaseResult testOrigins() {
        return new BaseResult().setResultCode(EResultCode.CODE1);
    }

    /**
     * 测试导出表格文件
     *
     * @param data     请求数据
     * @param response 响应
     * @return
     * @author LiCongLu
     * @date 2020-01-03 14:20
     */
    @ApiOperation(value = "导出数据表", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping("/export-excel-file")
    public void exportExcelFile(@RequestBody ExportData data, HttpServletResponse response) {
        testService.exportExcelFile(data, response);
    }

    /**
     * 测试上传图片文件
     *
     * @param data      请求数据
     * @param imageFile 上传图片文件
     * @return
     * @author LiCongLu
     * @date 2020-01-06 14:34
     */
    @ApiOperation("上传图片文件")
    @PostMapping(value = "/upload-image-file")
    public BaseResult uploadImageFile(BusinessData data, @RequestParam(value = "imageFile", required = false) MultipartFile imageFile) {
        return testService.uploadImageFile(data, imageFile);
    }

    /**
     * 生成二维码图片
     *
     * @param data
     * @return
     * @author LiCongLu
     * @date 2020-01-07 11:31
     */
    @ApiOperation("生成二维码")
    @PostMapping(value = "/load-qrcode-file")
    public BaseResult loadQRCodeFile(@RequestBody BusinessData data) {
        return testService.loadQRCodeFile(data);
    }

    /**
     * 验证请求数据
     *
     * @param data 请求数据
     * @return
     * @author LiCongLu
     * @date 2020-01-09 15:16
     */
    @ApiOperation("验证请求数据")
    @PostMapping(value = "/validate-data")
    public BaseResult validateData(@RequestBody ValidateData data) {
        return resultHandler(data, userItem -> testService.validateData(data, userItem));
    }
}